home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Clip Drag and Drop / MetafileClip / MetafileClip.cs next >
Encoding:
Text File  |  2001-01-15  |  2.7 KB  |  89 lines

  1. //-------------------------------------------
  2. // MetafileClip.cs ⌐ 2001 by Charles Petzold
  3. //-------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Imaging;
  7. using System.Windows.Forms;
  8.  
  9. class MetafileClip: MetafileConvert
  10. {
  11.      MenuItem miCut, miCopy, miPaste, miDel;
  12.  
  13.      public new static void Main()
  14.      {
  15.           Application.Run(new MetafileClip());
  16.      }
  17.      public MetafileClip()
  18.      {
  19.           Text = strProgName = "Metafile Clip";
  20.  
  21.                // Edit menu
  22.  
  23.           Menu.MenuItems[1].Popup += new EventHandler(MenuEditOnPopup);
  24.  
  25.                // Edit Cut menu item
  26.  
  27.           miCut = new MenuItem("Cu&t");
  28.           miCut.Click += new EventHandler(MenuEditCutOnClick);
  29.           miCut.Shortcut = Shortcut.CtrlX;
  30.           Menu.MenuItems[1].MenuItems.Add(miCut);
  31.  
  32.                // Edit Copy menu item
  33.  
  34.           miCopy = new MenuItem("&Copy");
  35.           miCopy.Click += new EventHandler(MenuEditCopyOnClick);
  36.           miCopy.Shortcut = Shortcut.CtrlC;
  37.           Menu.MenuItems[1].MenuItems.Add(miCopy);
  38.  
  39.                // Edit Paste menu item
  40.  
  41.           miPaste = new MenuItem("&Paste");
  42.           miPaste.Click += new EventHandler(MenuEditPasteOnClick);
  43.           miPaste.Shortcut = Shortcut.CtrlV;
  44.           Menu.MenuItems[1].MenuItems.Add(miPaste);
  45.  
  46.                // Edit Delete menu item
  47.  
  48.           miDel = new MenuItem("De&lete");
  49.           miDel.Click += new EventHandler(MenuEditDelOnClick);
  50.           miDel.Shortcut = Shortcut.Del;
  51.           Menu.MenuItems[1].MenuItems.Add(miDel);
  52.      }
  53.      void MenuEditOnPopup(object obj, EventArgs ea)
  54.      {
  55.           miCut.Enabled = 
  56.           miCopy.Enabled = 
  57.           miDel.Enabled = mf != null;
  58.           miPaste.Enabled = 
  59.                Clipboard.GetDataObject().GetDataPresent(typeof(Metafile));
  60.      }
  61.      void MenuEditCutOnClick(object obj, EventArgs ea)
  62.      {
  63.           MenuEditCopyOnClick(obj, ea);
  64.           MenuEditDelOnClick(obj, ea);
  65.      }
  66.      void MenuEditCopyOnClick(object obj, EventArgs ea)
  67.      {
  68.           Clipboard.SetDataObject(mf, true);
  69.      }
  70.      void MenuEditPasteOnClick(object obj, EventArgs ea)
  71.      {
  72.           IDataObject data = Clipboard.GetDataObject();
  73.  
  74.           if (data.GetDataPresent(typeof(Metafile)))
  75.                mf = (Metafile) data.GetData(typeof(Metafile));
  76.  
  77.           strFileName = "clipboard";
  78.           Text = strProgName + " - " + strFileName;
  79.           Invalidate();
  80.      }
  81.      void MenuEditDelOnClick(object obj, EventArgs ea)
  82.      {
  83.           mf = null;
  84.           strFileName = null;
  85.           Text = strProgName;
  86.           Invalidate();
  87.      }
  88. }
  89.